<!-- 设置组长、取消组长、移除小组 -->
<template>
  <dt-modal-edit ref='edit' :title='title' :label-width='100' okText='确定' :width='600'
    @ok='onOk'>
  </dt-modal-edit>
</template>

<script>
  import editMgr from './opt/editgroup'
  import teamsApi from '@/biz/buildingManagement/teams'

  export default {
    data() {
      return {
        info: {
          upDate: null, //生效日期
          cancelDate: null, //取消日期
          outGroupDate: null //离组日期
        },
        title: '',
        modelType: '',
        userMess: this.$dt.userInfo(),
      }
    },
    methods: {
      edit(data, type) {
        this.modelType = type
        switch (type) {
          case 'set':
            this.title = '设置组长';
            break;
          case 'cancel':
            this.title = '取消组长';
            break;
          case 'remove':
            this.title = '移除小组';
            break;
          default:
            break
        }
        this.info = Object.assign(this.info, data)
        this.show()
      },
      show() {
        this.$refs.edit.show(editMgr.options(this), this.info)
      },
      hide() {
        this.$refs.edit.hide()
      },
      update() {
        this.$refs.edit.update(editMgr.options(this, true))
      },
      onOk(data) {
        if (this.modelType == 'set' || this.modelType == 'cancel') {
          //设置组长、取消组长
          let params = {
            workNo: data.workNo,
            groupLeader: data.groupLeader == 1 ? 2 : 1,
            groupId: data.groupId,
            createId: this.userMess.userId,
            updateId: this.userMess.userId,
            groupUserId: data.groupUserId,
            upType: data.groupLeader == 1 ? 2 : 1, //1.生效 2.取消
            upDate: data.groupLeader == 1 ? data.cancelDate : data.upDate //生效或取消日期
          }
          teamsApi.updateGroupLeader(params).then((res) => {
            this.$Message.success('设置成功!')
            this.$emit('success')
            this.hide()
          })
        } else if (this.modelType == 'remove') {
          let params = {
            outGroupDate: data.outGroupDate,
            groupUserId: data.groupUserId,
            workNo: data.workNo,
            groupId: data.groupId,
            teamId: data.teamId
          }
          //移除小组
          teamsApi.removeGroupUser({ ...params }).then((res) => {
            this.$Message.success('移除成功!')
            this.$emit('success')
            this.hide()
          })
        }
      },
    }
  }
</script>

<style lang="scss" scoped>
</style>